/**
 * File: ReadDataWriter.java
 * Created by: mhaimel
 * Created on: 18 Aug 2009
 * CVS:  $Id: ReadDataWriter.java,v 1.2 2009/12/07 10:18:04 mhaimel Exp $
 */
package uk.ac.ebi.curtain.util.io;

import java.io.IOException;
import java.io.PrintWriter;

import org.apache.commons.logging.LogFactory;

import uk.ac.ebi.velvet.model.ReadData;
import uk.ac.ebi.velvet.model.Strand;

/**
 * @author mhaimel
 *
 */
public class ReadDataWriter extends AbstractWriter<ReadData> {

	public ReadDataWriter(PrintWriter out) {
		super(out);
		LogFactory.getLog(this.getClass()).debug("Create Read data writer for stream " + out);
	}

	/* ID | length | FilePos FWD | FilePos REV | FilePos UNKNOWN |    */
	@Override
	protected void _doWrite(ReadData bean) {
		getWriter().print(wrap(bean.getIdentifier()));
		printSep();
		getWriter().print(wrap(bean.getLenth()));
		printSep();
		printFilePosition(bean,Strand.FWD);
		printSep();
		printFilePosition(bean,Strand.REV);
		printSep();
		printFilePosition(bean,Strand.UNKOWN);
		getWriter().println();
	}

	private void printFilePosition(ReadData bean, Strand strand) {
		getWriter().print(bean.getFilePosition(strand));
	}

	@Override
	    public void close() throws IOException {
	    LogFactory.getLog(this.getClass()).debug("Close Read data writer for stream " + getWriter());
	    super.close();
	}
     	
}
